﻿using System;
using System.Collections;
using System.ComponentModel.DataAnnotations;
using System.Configuration;
namespace Cdn.Blogger.Models
{
    public class CDNSetting
    {
        public string User
        {
            get;
            set;
        }
        public string Subscription
        {
            get;
            set;
        }
        public string UserName
        {
            get;
            set;
        }
        [DataType(DataType.Password)]
        public string Password
        {
            get;
            set;
        }
        public string ContentUri
        {
            get;
            set;
        }
        public void Parse(string contentString)
        {
            string connectoinstring = string.IsNullOrEmpty(contentString) ? ConfigurationManager.AppSettings["ContentSetting"] : contentString;
            Hashtable table = new Hashtable();
            string[] vars = connectoinstring.Split(";".ToCharArray());
            string[] array = vars;
            for (int i = 0; i < array.Length; i++)
            {
                string v = array[i];
                string data = v.Trim();
                string[] keyval = data.Split("=".ToCharArray());
                table.Add(keyval[0].Trim().ToLower(), keyval[1].Trim());
            }
            this.User = (string)table["user"];
            this.Subscription = (string)table["subscription"];
            this.UserName = (string)table["username"];
            this.Password = (string)table["password"];
            this.ContentUri = (string)table["contenturi"];
        }
    }
}
